package cn.tanglong.topic;

import cn.tanglong.mq.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

public class Producer05 {
    // 交换机名称
    public static final String EXCHANGE_TOPIC = "EXCHANGE_TOPIC";

    public static void main(String[] args) throws Exception {
        Connection connection = null;
        Channel channel = null;
            //获取连接
            connection = ConnectionUtil.getConnection();
            //创建与Exchange的通道，每个连接可以创建多个通道，每个通道代表一个会话任务
            channel = connection.createChannel();

            // 创建交换机 交换机名字 类型
            channel.exchangeDeclare(EXCHANGE_TOPIC, BuiltinExchangeType.TOPIC);

            channel.basicPublish(EXCHANGE_TOPIC, "error", null, "啊哈！".getBytes());

            channel.basicPublish(EXCHANGE_TOPIC, "info", null, "啊哈！".getBytes());

            channel.basicPublish(EXCHANGE_TOPIC, "debug", null, "啊哈！".getBytes());

            System.out.println("使用成功！");
    }
}
